package com.tedu.servlet;

import com.tedu.dao.NewsTopicDao;
import com.tedu.pojo.Topic;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 向前端页面发送数据，
 * 再在页面显示数据
 */
public class IndexServlet extends HttpServlet {

    NewsTopicDao newsTopicDao;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        newsTopicDao = new NewsTopicDao();
        //调用dao获取全部新闻类型
        List<Topic> allTopic = newsTopicDao.getAllTopic();
        //发送要页面   req作用域里面
        req.setAttribute("allTopic",allTopic);
        //转发到  index。jsp
        req.getRequestDispatcher("index.jsp").forward(req,resp);


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);

    }
}
